﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Avatar.Model;
using AvatarHelper;

public partial class UserControl_News : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        using (var _adc = DBHelper.GetDataContext())
        {
            var _categorys = _adc.NewsCategory.Where(c => c.Default > 0).OrderBy(c => c.Default).Take(3).ToList();
            if (_categorys.Count > 0)
            {
                lbl_NewsTitleI.Text = _categorys[0] != null ? _categorys[0].Name : "暂无内容";
                list_Left.DataSource = _categorys[0].News.Select(n => new { n.ID, n.Title, n.PublishDate }).OrderBy(n => n.PublishDate).Take(8);
                list_Left.DataBind();

                lbl_NewsTitleII.Text = _categorys[1] != null ? _categorys[1].Name : "暂无内容";
                list_Middle.DataSource = _categorys[1].News.Select(n => new { n.ID, n.Title, n.PublishDate }).OrderBy(n => n.PublishDate).Take(8);
                list_Middle.DataBind();

                lbl_NewsTitleIII.Text = _categorys[2] != null ? _categorys[2].Name : "暂无内容";
                list_Right.DataSource = _categorys[2].News.Select(n => new { n.ID, n.Title, n.PublishDate }).OrderBy(n => n.PublishDate).Take(8);
                list_Right.DataBind();
            }
        }
    }
}
